#!/bin/bash

# Windows tools paths
NETSH="/mnt/c/WINDOWS/system32/netsh.exe"
FINDSTR="/mnt/c/WINDOWS/system32/findstr.exe"

# Network interface and IP addresses
INTERFACE="vEthernet (WSL)"
WIN_IP="172.18.16.1"
WSL_IP="${1:-172.18.16.101}" # Use the first parameter or default
WSL_BROADCAST="172.18.16.255"
WSL_NETMASK="24" 
WSL_LABEL="${2:-eth0:1}" # Use the second parameter or default

# Check Windows IP
$NETSH interface ip show addresses "$INTERFACE" | $FINDSTR /C:"$WIN_IP" > /dev/null

# If Windows IP not found, add it
if [ $? == 1 ]; then
    $NETSH interface ip add address "$INTERFACE" address=$WIN_IP/$WSL_NETMASK
fi

# Check WSL IP
ip addr show eth0 | grep -s "$WSL_IP/$WSL_NETMASK" > /dev/null

# If WSL IP not found, add it
if [ $? == 1 ]; then
    ip addr add $WSL_IP/$WSL_NETMASK broadcast $WSL_BROADCAST dev eth0 label $WSL_LABEL
fi

